﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Net.Formats.oEmbed.Tests
{
    /// <summary>
    /// Summary description for RequestTests
    /// </summary>
    [TestClass]
    public class IntegrationTests
    {
        public IntegrationTests( )
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void VimeoJSONTest( )
        {
            var url = new Uri( "http://vimeo.com/10260175" );


            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.JSON, ResourceUrl = url } );
            var response = request.CreateResponse( );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( VideoResponse ) );
        }

        [TestMethod]
        public void VimeoXmlTest( )
        {
            var url = new Uri( "http://vimeo.com/8813335" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.XML, ResourceUrl = url } );
            var response = request.CreateResponse( );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( VideoResponse ) );
        }

        [TestMethod( )]
        public void PollDaddyXMLTest( )
        {
            var url = new Uri( "http://polldaddy.com/oembed" );
            var resourceUrl = new Uri( "http://answers.polldaddy.com/poll/2064343" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.XML, ResourceUrl = resourceUrl, ProviderEndpoint = url } );
            var response = request.CreateResponse<RichResponse>( );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( RichResponse ) );
        }

        [TestMethod( )]
        public void PollDaddyJSONTest( )
        {
            var url = new Uri( "http://polldaddy.com/oembed" );
            var resourceUrl = new Uri( "http://answers.polldaddy.com/poll/2064343" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.JSON, ResourceUrl = resourceUrl, ProviderEndpoint = url } );
            var response = request.CreateResponse<RichResponse>( );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( RichResponse ) );
        }

        [TestMethod( )]
        public void SoundCloudXmlTest( )
        {
            var url = new Uri( "http://soundcloud.com/forss/flickermood" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.XML, ResourceUrl = url, ProviderEndpoint = null } );
            var response = request.CreateResponse( );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( RichResponse ) );
        }

        [TestMethod( )]
        public void SoundCloudJSONTest( )
        {
            var url = new Uri( "http://soundcloud.com/forss/flickermood" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.JSON, ResourceUrl = url, ProviderEndpoint = null } );
            var response = request.CreateResponse(  );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( RichResponse ) );
        }

        [TestMethod( )]
        public void FlickrXmlTest( )
        {
            var endpointUrl = new Uri( "http://www.flickr.com/services/oembed" );
            var resourceUrl = new Uri( "http://flickr.com/photos/biggreymare/4254161092/" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.XML, ProviderEndpoint = endpointUrl, ResourceUrl = resourceUrl } );
            var response = request.CreateResponse(  );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( PhotoResponse ) );
        }

        [TestMethod( )]
        public void FlickrJSONTest( )
        {
            var endpointUrl = new Uri( "http://www.flickr.com/services/oembed" );
            var resourceUrl = new Uri( "http://flickr.com/photos/biggreymare/4254161092/" );

            var request = new Request( new RequestParameters( ) { Format = ResponseFormat.JSON, ProviderEndpoint = endpointUrl, ResourceUrl = resourceUrl } );
            var response = request.CreateResponse(  );
            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( PhotoResponse ) );
        }        
    }
}
